<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>运输配送管理</title>
		<!-- 导入jquery核心类库 -->
		<script type="text/javascript" src="../../js/jquery-1.8.3.js"></script>
		<!-- 导入easyui类库 -->
		<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../js/easyui/ext/portal.css">
		<link rel="stylesheet" type="text/css" href="../../css/default.css">
		<script type="text/javascript" src="../../js/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../js/easyui/ext/jquery.portal.js"></script>
		<script type="text/javascript" src="../../js/easyui/ext/jquery.cookie.js"></script>
		
		<!--百度地图-->
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=rgGMGiiiaaCr2O2WMiiqYTxdplUGupp0"></script><script src="../../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
		<style type="text/css">body,
html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

#allmap {
	height: 100%;
	width: 100%;
}</style>
		<script type="text/javascript">$(function() {
	// 先将body隐藏，再显示，不会出现页面刷新效果
	$("body").css({
		visibility: "visible"
	});

	var transitToolbar = [{
		id: 'button-inoutstore',
		text: '出入库',
		iconCls: 'icon-add',
		handler: function() {
			
			//获取选择行
			var row = $("#transitGrid").datagrid("getSelected");
			if (row == null){
				$.messager.alert('警告','必须选中一条记录','warning');
				return;
			}
			
			if (row.status == '出入库中转'){
				//清空$inOutStoreTransitInfoView"
				$("#inOutStoreTransitInfoView").html("");
				
				//向表单隐藏域保存id
				$("#inOutStoreId").val(row.id);
				$("#inOutStoreTransitInfoView").append("运单号:"+row.wayBill.wayBillNum+"</br>");
				$("#inOutStoreTransitInfoView").append("货物类型:"+row.wayBill.goodsType+"</br>");
				$("#inOutStoreTransitInfoView").append("发货地:"+row.wayBill.sendAddress+"</br>");
				$("#inOutStoreTransitInfoView").append("收货地:"+row.wayBill.recAddress+"</br>");
				$("#inOutStoreTransitInfoView").append("物流信息:"+row.transferInfo+"</br>");
				
				$("#inoutstoreWindow").window('open');
			}else {
				$.messager.alert('警告','进行出入库操作,必须操作状态为出入库中转的运单','warning');
				return;
			}
			
		}
	}, {
		id: 'button-delivery',
		text: '开始配送',
		iconCls: 'icon-print',
		handler: function() {
			
			//获取选择行
			var row = $("#transitGrid").datagrid("getSelected");
			if (row == null){
				$.messager.alert('警告','必须选中一条记录','warning');
				return;
			}
			
			if (row.status == '到达网点'){
				$("#deliveryTransitInfoView").html("");
				
				//向表单隐藏域保存id
				$("#deliveryId").val(row.id);
				$("#deliveryTransitInfoView").append("运单号:"+row.wayBill.wayBillNum+"</br>");
				$("#deliveryTransitInfoView").append("货物类型:"+row.wayBill.goodsType+"</br>");
				$("#deliveryTransitInfoView").append("发货地:"+row.wayBill.sendAddress+"</br>");
				$("#deliveryTransitInfoView").append("收货地:"+row.wayBill.recAddress+"</br>");
				$("#deliveryTransitInfoView").append("物流信息:"+row.transferInfo+"</br>");
				
				$("#deliveryWindow").window('open');
			}else {
				$.messager.alert('警告','该运单未到达网点','warning');
				return;
			}
			
			
		}
	}, {
		id: 'button-sign',
		text: '签收录入',
		iconCls: 'icon-save',
		handler: function() {
			//获取选择行
			var row = $("#transitGrid").datagrid("getSelected");
			if (row == null){
				$.messager.alert('警告','必须选中一条记录','warning');
				return;
			}
			
			if (row.status == '开始配送'){
				$("#signInfoView").html("");
				
				//向表单隐藏域保存id
				$("#signId").val(row.id);
				$("#signInfoView").append("运单号:"+row.wayBill.wayBillNum+"</br>");
				$("#signInfoView").append("货物类型:"+row.wayBill.goodsType+"</br>");
				$("#signInfoView").append("发货地:"+row.wayBill.sendAddress+"</br>");
				$("#signInfoView").append("收货地:"+row.wayBill.recAddress+"</br>");
				$("#signInfoView").append("物流信息:"+row.transferInfo+"</br>");
				
				$("#signWindow").window('open');
			}else {
				$.messager.alert('警告','签收录入操作只能针对开始配送状态运单','warning');
				return;
			}
			
		}
	}, {
		id: 'button-transit',
		text: '运输路径',
		iconCls: 'icon-search',
		handler: function() {
			//获取选择行
			var row = $("#transitGrid").datagrid("getSelected");
			if (row == null){
				$.messager.alert('警告','必须选中一个运单','warning');
				return;
			}
			// 百度地图API功能
			var map = new BMap.Map("allmap");
			map.centerAndZoom('北京',11);
			map.enableScrollWheelZoom(true);   //启用滚轮放大缩小，默认禁用
			//三种驾车策略：最少时间，最短距离，避开高速
			var routePolicy = [BMAP_DRIVING_POLICY_LEAST_TIME, BMAP_DRIVING_POLICY_LEAST_DISTANCE, BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
			var start = row.wayBill.sendAddress;
			var end = row.wayBill.recAddress;
			//获取DrivingRoute
			var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true},policy: routePolicy[0]});
			
			if (row.id == "2"){
				driving.search(start,end,{waypoints:['南京']});
			}else{
				driving.search(start,end);
				
			}
			// 弹出窗口
			$("#transitPathWindow").window('open');
		}
	}, {
		id: 'button-path',
		text: '实时配送路径',
		iconCls: 'icon-search',
		handler: function() {
			$("#deliveryInTimePathWindow").window('open');
		}
	}];

	var transitColumns = [
		[{
			field: 'id',
			title: '编号',
			width: 30
		}, {
			field: 'wayBillNum',
			title: '运单号',
			width: 100,
			formatter: function(data, row, index) {
				if(row.wayBill.wayBillNum != undefined) {
					return row.wayBill.wayBillNum;
				}
			}
		}, {
			field: 'sendName',
			title: '寄件人姓名',
			width: 100,
			formatter: function(data, row, index) {
				return row.wayBill.sendName;
			}

		}, {
			field: 'sendAddress',
			title: '寄件地址',
			width: 100,
			formatter: function(data, row, index) {
				return row.wayBill.sendAddress;
			}
		}, {
			field: 'recName',
			title: '收件人姓名',
			width: 100,
			formatter: function(data, row, index) {
				return row.wayBill.recName;
			}
		}, {
			field: 'recAddress',
			title: '收件地址',
			width: 100,
			formatter: function(data, row, index) {
				return row.wayBill.recAddress;
			}
		}, {
			field: 'goodsType',
			title: '托寄物',
			width: 100,
			formatter: function(data, row, index) {
				return row.wayBill.goodsType;
			}
		}, {
			field: 'status',
			title: '运输状态',
			width: 100
		}, {
			field: 'outletAddress',
			title: '网点地址',
			width: 100
		}, {
			field: 'transferInfo',
			title: '物流信息',
			width: 100
		}]
	];

	// 运输配送管理 表格定义 
	$('#transitGrid').datagrid({
		iconCls: 'icon-forward',
		url: '../../transit_pageQuery.action',
		fit: true,
		border: false,
		rownumbers: true,
		striped: true,
		pageList: [20, 50, 100],
		pagination: true,
		idField: 'id',
		singleSelect: true,
		toolbar: transitToolbar,
		columns: transitColumns
	});
	
	//保存出入库信息
	$("#inoutStoreSave").click(function(){
		
		if($("#inoutStoreForm").form('validate')){
			$("#inoutStoreForm").submit();
		}else{
			$.messager.alert('警告','表单存在非法字段','warning');
		}
	});

	//开始配送功能
	$("#deliverySave").click(function(){
			
		if($("#deliveryForm").form('validate')){
			$("#deliveryForm").submit();
		}else{
			$.messager.alert('警告','表单存在非法字段','warning');
		}
	});
	
	//开始签收功能
	$("#signSave").click(function(){
			
		if($("#signForm").form('validate')){
			$("#signForm").submit();
		}else{
			$.messager.alert('警告','表单存在非法字段','warning');
		}
	});
});</script>
	</head>

	<body class="easyui-layout" style="visibility:hidden;">

		<div data-options="region:'center'">
			<table id="transitGrid"></table>
		</div>

		<div class="easyui-window" title="出入库" id="inoutstoreWindow" modal="true" closed="true" collapsible="false" minimizable="false" maximizable="false" style="top:100px;left:200px;width: 600px; height: 300px">
			<div region="north" style="height:30px;overflow:hidden;" split="false" border="false">
				<div class="datagrid-toolbar">
					<a id="inoutStoreSave" icon="icon-save" href="#" class="easyui-linkbutton" plain="true">保存</a>
				</div>
			</div>
			<div region="center" style="overflow:auto;padding:5px;" border="false">
				<form id="inoutStoreForm" method="post" action="../../inoutstore_save.action">
					<table class="table-edit" width="80%" align="center">
						<tr class="title">
							<td colspan="2">出入库操作</td>
						</tr>
						<tr>
							<td>运单信息</td>
							<td>
								<input type="hidden" name="transitInfoId" id="inOutStoreId" />
								<span id="inOutStoreTransitInfoView"></span>
						</tr>
						<tr>
							<td>操作</td>
							<td>
								<select name="operation" class="easyui-combobox">
									<option value="入库">入库</option>
									<option value="出库">出库</option>
									<option value="到达网点">到达网点</option>
								</select>
							</td>
						</tr>
						<tr>
							<td>仓库或网点地址</td>
							<td>
								<input type="text" name="address" size="40" class="easyui-validatebox" required="true"/>
							</td>
						</tr>
						<tr>
							<td>描述</td>
							<td>
								<textarea rows="3" cols="40" name="description" class="easyui-validatebox" required="true"></textarea>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>

		<div class="easyui-window" title="开始配送" id="deliveryWindow" modal="true" closed="true" collapsible="false" minimizable="false" maximizable="false" style="top:100px;left:200px;width: 600px; height: 300px">
			<div region="north" style="height:30px;overflow:hidden;" split="false" border="false">
				<div class="datagrid-toolbar">
					<a id="deliverySave" icon="icon-save" href="#" class="easyui-linkbutton" plain="true">保存</a>
				</div>
			</div>
			<div region="center" style="overflow:auto;padding:5px;" border="false">
				<form id="deliveryForm" method="post" action="../../delivery_save.action">
					<table class="table-edit" width="80%" align="center">
						<tr class="title">
							<td colspan="2">开始配送</td>
						</tr>
						<tr>
							<td>运单信息</td>
							<td>
								<input type="hidden" name="transitInfoId" id="deliveryId" />
								<span id="deliveryTransitInfoView"></span>
						</tr>
						<tr>
							<td>快递员工号</td>
							<td>
								<input type="text" required="true" name="courierNum" class="easyui-validatebox" required="true"/>
							</td>
						</tr>
						<tr>
							<td>快递员姓名</td>
							<td>
								<input type="text" required="true" name="courierName" class="easyui-validatebox" required="true"/>
							</td>
						</tr>
						<tr>
							<td>描述</td>
							<td>
								<textarea rows="3" cols="40" name="description" class="easyui-validatebox" required="true"></textarea>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>

		<div class="easyui-window" title="签收录入" id="signWindow" modal="true" closed="true" collapsible="false" minimizable="false" maximizable="false" style="top:100px;left:200px;width: 600px; height: 300px">
			<div region="north" style="height:30px;overflow:hidden;" split="false" border="false">
				<div class="datagrid-toolbar">
					<a id="signSave" icon="icon-save" href="#" class="easyui-linkbutton" plain="true">保存</a>
				</div>
			</div>
			<div region="center" style="overflow:auto;padding:5px;" border="false">
				<form id="signForm" method="post" action="../../sign_save.action">
					<table class="table-edit" width="80%" align="center">
						<tr class="title">
							<td colspan="2">签收录入</td>
						</tr>
						<tr>
							<td>运单信息</td>
							<td>
								<input type="hidden" name="transitInfoId" id="signId" />
								<span id="signInfoView"></span>
						</tr>
						<tr>
							<td>签收人</td>
							<td>
								<input type="text" required="true" name="signName" class="easyui-validatebox" required="true"/>
							</td>
						</tr>
						<tr>
							<td>签收日期</td>
							<td>
								<input type="text" class="easyui-datebox" required="true" name="signTime" class="easyui-validatebox" required="true"/>
							</td>
						</tr>
						<tr>
							<td>签收状态</td>
							<td colspan="3">
								<select class="easyui-combobox" style="width:150px" name="signType">
									<option value="正常">正常</option>
									<option value="返单">返单</option>
									<option value="转发签收">转发签收</option>
								</select>
							</td>
						</tr>
						<tr>
							<td>异常备注</td>
							<td>
								<textarea name="errorRemark" rows="4" cols="40"></textarea>
							</td>
						</tr>
						<tr>
							<td>描述</td>
							<td>
								<textarea rows="3" cols="40" name="description" class="easyui-validatebox" required="true"></textarea>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>

		<div class="easyui-window" title="运输路径查看" id="transitPathWindow" modal="true" closed="true" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:100px;width: 800px; height: 400px">
			<div id="allmap"></div>
		</div>

		<div class="easyui-window" title="实时配送路径" id="deliveryInTimePathWindow" modal="true" closed="true" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:100px;width: 800px; height:400px">
		</div>
	</body>

</html>